package net
{
	import data.Globals;
	
	import flash.system.Security;
	import flash.system.SecurityDomain;
	
	import ua.kiev.gcore.logger.Logger;
	import ua.kiev.gcore.net.ServerProxy;
	import ua.kiev.gcore.net.builder.ICommandBuilder;
	import ua.kiev.gcore.net.connections.Connection;
	import ua.kiev.gcore.net.connections.event.CommunicateEvent;
	import ua.kiev.gcore.net.parser.ICommandParser;
	import ua.kiev.gcore.net.sender.CommandSender;
	import ua.kiev.gogames.gofishing.model.dictionaries.CommandDictionary;
	import ua.kiev.gogames.gofishing.model.net.Connections;
	import ua.kiev.gogames.gofishing.model.net.ISender;
	import ua.kiev.gogames.gofishing.model.net.commands.Buy2Server;
	import ua.kiev.gogames.gofishing.model.net.commands.Cast2Server;
	import ua.kiev.gogames.gofishing.model.net.commands.Catch2Server;
	import ua.kiev.gogames.gofishing.model.net.commands.Equip2Server;
	import ua.kiev.gogames.gofishing.model.net.commands.EquipSlot2Client;
	import ua.kiev.gogames.gofishing.model.net.commands.EquipSlot2Server;
	import ua.kiev.gogames.gofishing.model.net.commands.GetDesignData;
	import ua.kiev.gogames.gofishing.model.net.commands.GetUserData2Server;
	import ua.kiev.gogames.gofishing.model.net.commands.Join2Server;
	import ua.kiev.gogames.gofishing.model.net.commands.Sell2Server;
	import ua.kiev.gogames.gofishing.model.net.commands.SetUserDataDefault2Server;
	import ua.kiev.gogames.gofishing.model.net.commands.Strike2Server;
	import ua.kiev.gogames.gofishing.model.net.protocol.bson.BSONBuilder;
	
	public class BSONSender extends CommandSender implements ISender
	{
		public function BSONSender()
		{
			super();
			
		}
		
		public function init():void
		{
			Logger.INFO("Connecting to: " + Globals.serverAddres + ":" + Globals.serverPort);
			initConnection(Globals.serverAddres, Globals.serverPort, ServerProxy.SOCET, new BSONBuilder(), new BSONParser());
		}
		override public function connectSecsesfulHandler(event:CommunicateEvent):void{
			super.connectSecsesfulHandler(event);
			Logger.INFO(event.message);
		}
		override public function connectFaildHandler(event:CommunicateEvent):void{
			super.connectFaildHandler(event);
			Logger.Trace(event.message);
		}
		
		public function join():void
		{
			Logger.Trace("[Client] Join");
			send(new Join2Server("evgeniikim@gmail.com", "", "e0659490-258b-406c-90ae-69376eafe91f", "CD82490C-AF84-4E9C-AF99-F4C4D584D9D7"), CommandDictionary.Join);
		}
		
		public function designData():void{
			Logger.Trace("[Client] GetDesignData");
			send(new GetDesignData(), CommandDictionary.GetDesignData);
		}
		
		public function userData():void
		{
			Logger.Trace("[Client] GetUserData");
			send(new GetUserData2Server(), CommandDictionary.GetUserData);
		}
		
		public function getFriends():void
		{
			
		}
		
		public function getQuestss():void
		{
			
		}
		
		public function travel(loc_id:String):void
		{
		}
		
		public function buyItem(Gid:String, count:int):void
		{
			Logger.Trace("[Client] Buy Gid: " + Gid + " Count: " + count.toString());
			send(new Buy2Server(Gid, count), CommandDictionary.Buy);
		}
		
		public function sellItem(uid:String, count:int, storageType:String):void
		{
			Logger.Trace("[Client] Sell Uid: " + uid + " Count: " + count.toString() + " storageType: " + storageType);
			send(new Sell2Server(uid, count, storageType), CommandDictionary.Sell);
		}
		
		public function useItem(uid:String, entity:String, count:int):void
		{
			Logger.Trace("[Client] Equip2Server");
			send(new Equip2Server(uid, entity, count), CommandDictionary.Equip);
		}
		public function useSlot(slotType:String):void{
			Logger.Trace("[Client] EquipSlot2Server");
			send(new EquipSlot2Server(slotType), CommandDictionary.EquipSlot);
		}
		
		public function rodCast():void
		{
			Logger.Trace("[Client] Cast2Server");
			send(new Cast2Server(), CommandDictionary.Cast);
		}
		
		public function rodStrike(result:Boolean):void
		{
			Logger.Trace("[Client] Strike2Server");
			send(new Strike2Server(), CommandDictionary.Strike);
		}
		
		public function rodOverload():void
		{
		}
		
		public function rodPullOut(goal:Boolean):void
		{
			Logger.Trace("[Client] Catch2Server");
			send(new Catch2Server(goal), CommandDictionary.Catch);
		}
		
		public function tradeCollection(collection_id:String):void
		{
		}
		
		public function removeEnergy():void
		{
		}
		
		public function updateEnergy():void
		{
		}
		public function setUserDataDefault(UserBackpack:Boolean, UserProgressData:Boolean, UserPaperdoll:Boolean):void{
			Logger.Trace("[Client] SetUserDataDefault");
			send(new SetUserDataDefault2Server(UserBackpack, UserProgressData, UserPaperdoll), CommandDictionary.SetUserDataDefault);
		}
	}
}